/* 
 * File:   map.h
 * Author: cow
 *
 * Created on April 25, 2011, 9:25 PM
 */

#ifndef MAP_H
#define	MAP_H

//includes-----------------------------
#include <gtkmm/builder.h>
#include <cairomm/cairomm.h>
#include <gtkmm/window.h>
#include <gtkmm/drawingarea.h>
#include <glibmm/ustring.h>
#include <gdk/gdkkeysyms.h>
#include <map>
#include <iostream>
#include "../PlayerData/unit.h"
#include "../PlayerData/mapdata.h"
#include "../PlayerData/players.h"
#include "../Main.h"
#include "cursor.h"
using namespace std;
//defines------------------------------
namespace mapscreen{
#define mapscrDesig "gameMap"
#define mapContDesig "MapBox"
#define infoBoxDesig "infoBox"
#define pixWid 50
#define pixHgt 50
#define wtype Glib::RefPtr<Gdk::Window>
#define ctype Cairo::RefPtr<Cairo::Context>
}

//prototypes---------------------------
namespace mapscreen{
class mapcontainer;
class infoscr;
class mapscr;
class mappixel;
class fleetpixel;
class terrainpixel;
class cursorpixel;
}

//definitions--------------------------
namespace mapscreen{
//mapcontainer+++++
class mapcontainer{
public:
private:
};
//infoscr++++++++++
class infoscr : public Gtk::VBox{
public:
	//constructors------
	static infoscr* gsInfoScr();
	infoscr(BaseObjectType* obj, const Glib::RefPtr<Gtk::Builder>& window);
	~infoscr();
	//access------------
	//manips------------
	void draw();
private:
	//constructors------
	infoscr();
	
	static infoscr* single;
	Units::unit* activeFleet;
};
//mapscr+++++++++++
class mapscr : public Cursor::cursorServer, public Gtk::DrawingArea{
public:
	//constructors------
	static mapscr* gsMapScr();
	mapscr(BaseObjectType* obj, const Glib::RefPtr<Gtk::Builder>& window);
	~mapscr();
	//manips------------
    void draw();
protected:
	//load functions----
	void loadFleets();
	void loadTerrain();
	//controll----------
	bool process(int x, int y);
    bool on_key_press_event(GdkEventKey* key);
	bool on_button_press_event(GdkEventButton* btn);
	bool on_expose_event(GdkEventExpose* exp);
private:
	//constructors------
	mapscr();

	static mapscr* single;
	cursorpixel* curp;
	int startX, startY;
    int offsetX, offsetY;
	Units::unit* activeFleet;
	std::map<pair<int, int>, terrainpixel*> terrainMap;
	std::map<pair<int, int>, fleetpixel*> fleetsMap;
	
	//widget size info;
	static int width;
	static int height;
};
//mappixel+++++++++
class mappixel{
public:
    virtual void draw(int x, int y, ctype ct) = 0;
private:
};
//fleetPixel+++++++
class fleetpixel : public mappixel, public Cursor::cursorListener{
public:
    fleetpixel(Units::unit* u);
    virtual void draw(int x, int y, ctype ct);
protected:
	virtual void signal_curs_enter(int x, int y);
	virtual void signal_curs_move(int x, int y);
	void drawSpindle(int x, int y, ctype ct);
	void drawTriangle(int x, int y, ctype ct);
	void drawBroad(int x, int y, ctype ct);
	void drawArtl(int x, int y, ctype ct);
	void drawSiege(int x, int y, ctype ct);
	void drawFArcs(int x, int y, ctype ct);
private:
    Units::unit* rep;
	int selx, sely;
	bool seled;
	//rotation info
	static const double right;
	static const double left;
	static const double down;
};
//terrainpixel+++++
class terrainpixel : public mappixel{
public:
	terrainpixel(mapdata::terrain* t);
	virtual void draw(int x, int y, ctype ct);
	bool compare(mapdata::terrain* t);
private:
	mapdata::terrain* ter;
};
//cursorpixel++++++
class cursorpixel : public mappixel{
public:
	cursorpixel();
	virtual void draw(int x, int y, ctype ct);
};
}
#endif	/* MAP_H */

